﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Toenda.Foundation {
	/// <summary>
	/// Extends the Char class
	/// </summary>
	public static class CharExtensions {
		/// <summary>
		/// Check if a char symbol is in a char array
		/// </summary>
		/// <param name="instance">The char array.</param>
		/// <param name="symbol">The char symbol.</param>
		/// <returns></returns>
		public static bool Contains(this char[] instance, char symbol) {
			foreach(char c in instance) {
				if(c == symbol) {
					return true;
				}
			}

			return false;
		}

		/// <summary>
		/// Determines whether [is forbidden character] [the specified character].
		/// </summary>
		/// <param name="instance">The character.</param>
		/// <returns>
		///     <c>true</c> if [is forbidden character] [the specified character]; otherwise, <c>false</c>.
		/// </returns>
		public static bool IsForbiddenCharacter(this char instance) {
			string pattern = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.";

			return instance.ToString().HasForbiddenCharacters(pattern, false);
		}

		/// <summary>
		/// Converts a char array to a string list
		/// </summary>
		/// <param name="instance">The instance.</param>
		/// <returns></returns>
		public static List<string> ToStringList(this char[] instance) {
			return new List<char>(instance).ConvertAll<string>(item => {
				return item.ToString();
			});
		}
	}
}
